package com.ssm.handler;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.ssm.pojo.Student;
import com.ssm.service.StudentManagerService;

@Controller
public class StudentManagerHandler {
	@Autowired
	private StudentManagerService studentManagerService;

	@ModelAttribute
	public void getEmployee(@RequestParam(value = "stuId", required = false) Integer stuId, Map<String, Object> map) {
		if (null != stuId) {
			Student student = this.studentManagerService.getStu(stuId);
			map.put("abc", student);
		}

	}

	@RequestMapping("/add")
	public String addStu(Map<String, Object> map) {
		map.put("student", new Student());
		return "student/addstudent";
	}
	@RequestMapping("/addsave")
	public String addStuSave(Student student,Map<String, Object> map) {
		this.studentManagerService.addStu(student);
		return "student/success";
	}

	@RequestMapping("/del/{stuId}")
	public String delStu(@PathVariable("stuId") Integer stuId, Map<String, Object> map) {
		this.studentManagerService.delStu(stuId);
		return "student/success";
	}

	@RequestMapping("/upd/{stuId}")
	public String updStu(@PathVariable("stuId") Integer stuId, Map<String, Object> map) {
		map.put("student", this.studentManagerService.getStu(stuId));
		return "student/updstudent";
	}
	@RequestMapping("/updsave")
	public String updStuSave(@ModelAttribute("abc") Student student, Map<String, Object> map) {
		this.studentManagerService.updStu(student);
		return "student/success";
	}
	@RequestMapping("/findAll")
	public String findAllStu(Map<String, Object> map) {
		List<Student> students = this.studentManagerService.findAllStu();
		map.put("students", students);
		return "student/list";
	}

}
